}
However, if we need to create a local variable of type array, we must
store it using the memory keyword to save it in the temporary
storage, as shown as follows:
// SPDX-License-Identifier: Some Identifier
pragma solidity ^0.8.10;
contract Types {
function getScores() public pure returns (uint8[5] memory){
uint8[5] memory scores = [10, 20, 30, 40, 50];
return scores;
}
}
2.5.10.2.2 Struct
I find Struct to be the most interesting complex data type that can
further be comprised of many other simple data types, arrays, and
mappings.
2.5.10.2.3 Mappings
Mappings are always the state variables and are similar to the hash
tables in java, where the key-value pair data is stored.
Please note that Integers, fixed number, Boolean, byte, enum, and
address can be copied by value, whereas Array, Struct, and String
are passed by reference. Please note that passing by reference
means that you are pointing to a memory location of the variable.
There are mainly two types of variables available in Solidity – State
variables and Local variables. We consider them as the Global
variables and Local variables, just as any other language.
2.5.10.3 Constant and Immutable State Variables
A State variable can be declared as either “constant” or “immutable”
if it needs to have a fixed value. However, in case of the constant,
the value has to be set in the compilation time, whereas for the